function receive(prod)
  local status, value = coroutine.resume(producer)
  return value
end

function send(x)
  coroutine.yield(x)
end

producer = coroutine.create(
  function ()
    while true do
      local x = io.read()
      send(x)
    end
  end)

function consumer(prod)
  while true do
    local x = receive(prod)
    io.write(x, "\n")
  end
end

consumer(producer)
coroutine.resume(producer)

